#include "primarykeyconstraint.h"

#include "columnlist.h"
#include <stack>

PrimaryKeyConstraint::PrimaryKeyConstraint(ColumnList * columns)
{
    if(columns == NULL) this->columns = NULL;
    else this->columns = columns->clone();
}

PrimaryKeyConstraint::~PrimaryKeyConstraint()
{
    delete columns; columns = NULL; // NULL
}

PrimaryKeyConstraint::PrimaryKeyConstraint(const PrimaryKeyConstraint& other)
{
    if(other.columns != NULL) columns = other.columns->clone();
    else columns = NULL;
}

ColumnList* PrimaryKeyConstraint::getColumns() const
{
    return columns;
}

void PrimaryKeyConstraint::setColumns(ColumnList * columns)
{
    delete this->columns; this->columns = NULL;
    this->columns = columns->clone();
}

void PrimaryKeyConstraint::addColumn(Column * column)
{
    if(columns == NULL) columns = new ColumnList();          // if NULL
    columns->addColumn(column);
}

void PrimaryKeyConstraint::addColumn(const string & column)
{
    if(columns == NULL) columns = new ColumnList();          // if NULL
    columns->addColumn(column);
}

string PrimaryKeyConstraint::toString()
{
    string str = "[PRIMARY KEY: ";
    if(columns != NULL){
        str = str + columns->toString();
    } //if
    return str + "]";
}

TableConstraint * PrimaryKeyConstraint::clone()
{
    return new PrimaryKeyConstraint(* this);
}

